CLR & Garbage Collector (GC)
1 min readRapid overview
Garbage Collection in JavaScript Engines
JavaScript engines use generational garbage collectors to reclaim memory from unreachable objects.
Basics
- Young generation: Short-lived objects collected frequently.
- Old generation: Long-lived objects collected less often.
- Stop-the-world pauses: GC can pause execution, so avoid heavy allocations in hot paths.
Common leak patterns
- Detached DOM nodes held by closures.
- Event listeners not removed on cleanup.
- Global caches with no eviction policy.
How to monitor
- Use Chrome DevTools Memory panel for heap snapshots.
- Track long tasks and allocation spikes.
Interview prompt
- Describe how you would find a memory leak in a React app.